import numpy as np
import matplotlib.pyplot as plt

# 定义 sinc 函数
def sinc(x):
    return np.sin(x) / x if x != 0 else 1

# 定义 f(Ω) 函数
def f(omega, tau, t):
    sinc_value = sinc(omega * tau / 2)
    return tau * sinc_value + tau * sinc_value * np.exp(-1j * omega * t) + tau * sinc_value * np.exp(1j * omega * t)

# 生成Ω值
omega = np.linspace(-20, 20, 400)
t = 1  # 假定 t = 1
tau = 1  # 假定 τ = 1

# 计算函数值
y = []
for item in omega:
    y_item = np.real(f(item, tau, t))
    y.append(y_item)

# 绘图
plt.plot(omega, y, label=r"$f(\Omega) = \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) + \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) e^{-j\Omega t} + \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) e^{j\Omega t}$")
plt.title(r"Graph of $f(\Omega) = \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) + \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) e^{-j\Omega t} + \tau \left( \frac{\sin \left( \frac{\Omega \tau}{2} \right)}{\frac{\Omega \tau}{2}} \right) e^{j\Omega t}$")
plt.xlabel(r"$\Omega$")
plt.ylabel(r"$f(\Omega)$")
plt.grid(True)
plt.legend()
plt.show()